#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_set>

using namespace std;

static bool pandigital(int a, int b, int c) {
    string s = to_string(a) + to_string(b) + to_string(c);
    if (s.size() != 9)
        return false;
    sort(s.begin(), s.end());
    for (int i = 0; i < s.size(); ++i) {
        if (i + 1 != s[i] - '0')
            return false;
    }
    return true;
}

int main() {
    unordered_set<int> s;
    for (int i = 1; i < 10; ++i) {
        for (int j = 1000; j < 10000; ++j) {
            int k = i * j;
            if (pandigital(i, j, k)) {
                cout << i << " * " << j << " = " << k << endl;
                s.insert(k);
            }
        }
    }
    for (int i = 10; i < 100; ++i) {
        for (int j = 100; j < 1000; ++j) {
            int k = i * j;
            if (pandigital(i, j, k)) {
                cout << i << " * " << j << " = " << k << endl;
                s.insert(k);
            }
        }
    }
    cout << accumulate(s.begin(), s.end(), 0) << endl; // 11305589
}